<template>
    <div>
        <slot></slot>
    </div>
</template>
<script>
    import Emitter from '../../../node_modules/iview/src/mixins/emitter';
    import {findComponentsDownward} from '../../../node_modules/iview/src/utils/assist'

    export default {
        name: 'SwitchGroup',
        mixins: [ Emitter ],
        props:{
            value: {
                type: [String, Number],
                default: ''
            },
            vertical: {
                type: Boolean,
                default: false
            },
            childName:{
                type:String,
                default:"HorizonSwitch"
            }
        },
        data(){
            return{
                currentValue: this.value,
                childrens: []
            }
        },
        mounted(){
            this.updateValue()
        },
        methods:{
            updateValue(){
                const value = this.value
                this.childrens = findComponentsDownward(this,this.childName);
                if(this.childrens){
                    //在这里做唯一性处理
                    this.childrens.forEach(child=>{
                        child.currentValue = value == child.label
                        child.group = true
                    })
                }
            },
            change(data){
                this.currentValue = data.value
                this.updateValue()
                this.$emit('input',data.value)
                this.$emit('on-change',data)
//                this.dispath('')
            }
        },
        watch:{
            value(){
                this.updateValue()
            }
        }
    }
</script>